using System;
using System.Collections.Generic;
using System.Text;

namespace Weazel.Toad.Application.Actions
{
    public class InsertMemoryIpBlock
      : ActionBase
    {
        private static string description =
            "ipblock memory (                      \n" +                                 
            "   in ram_rd   		: ns(1);       \n" +
            "   in ram_wr   		: ns(1);       \n" +
            "   in ram_addr 		: ns(32);      \n" +
            "   in ram_data 		: ns(32);      \n" +
            "   out device_data 	: ns(32)       \n" +
            "){                                    \n" +                     
            "   iptype \"memory\";                 \n" +
            "   ipparm \"file=c:\\myfile.txt\";    \n" +
            "   ipparm \"size=0x10000\";           \n" +
            "}\n";

        public InsertMemoryIpBlock()
        {
            Enabled = false;

            Application.Instance.SelectedItemChanged +=
              new EventHandler<SelectedItemChangedEventArgs>(Instance_SelectedItemChanged);
        }

        public override void Execute(object sender, EventArgs e)
        {
            if (Application.Instance.SelectedItem is Items.GezelTextFile)
            {

                Items.GezelTextFile file =
                      Application.Instance.SelectedItem as Items.GezelTextFile;

                file.TextEditor.TextAreaControl.TextArea.InsertString(description);
            }
        }

        void Instance_SelectedItemChanged(object sender, SelectedItemChangedEventArgs e)
        {
            if (e.SelectedItem is Items.GezelTextFile)
            {
                Enabled = true;
            }
            else
            {
                Enabled = false;
            }
        }
    }
}
